package com.meta.context.validate;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.schema.JSONSchema;
import com.alibaba.fastjson2.schema.ValidateResult;

public class MetaValidate {
    public static void main(String[] args) {
        // JSON数据
        String json = "{\"name1\":\"John\", \"age\":30}";

        // JSON Schema定义
        String schemaStr = "{ \"type\": \"object\",\n" +
                "   \"properties\": {\n" +
                "      \"name\": {\"type\": \"string\"},\n" +
                "      \"age\": {\"type\": \"integer\"}\n" +
                "   },\n" +
                "   \"required\": [\"name\", \"age\"]\n" +
                "}";

        JSONSchema schema = JSONSchema.of(JSON.parseObject(schemaStr));
        System.out.println(schema);
        ValidateResult result = schema.validate(JSON.parse(json));

        System.out.println(result.getMessage());
    }
}
